﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ReadBooks.Comm;
using System;
using System.Collections.Generic;

namespace EFRepository
{
    public class EFRepoModule:Module
    {
        public override void Initialize()
        {
          //  Database.SetInitializer(new CreateDatabaseIfNotExists<ABPCMSDbContext>());
            var connection = "Filename=./ef.db";
            IocManager.AddDbContext<ICommRepository, EFCommContext>(options => options.UseSqlite(connection));
            
           IocManager.AddDbContext<EFCommContext>(options => options.UseSqlite(connection, b => b.MigrationsAssembly("WXSend"))
          );
            /*
              Install-Package Microsoft.EntityFrameworkCore.Tools 
             安装好以后，我们在 project.json tools 节点下
            开始创建数据库 使用 dotnet ef

打开文件夹的命令行，

输入

　　dotnet ef migrations add MyFirstMigration

　　dotnet ef database update

这样我们就创建好了数据库。更多命令请 dotnet ef -h
             */


        }
    }

    public abstract class Module
    {
        /// <summary>
        /// Gets a reference to the IOC manager.
        /// </summary>
        public IServiceCollection IocManager
        {
            get;
             set;
        }

        /// <summary>
        /// Gets a reference to the ABP configuration.
        /// </summary>
        protected internal Dictionary<string,Object> Configuration
        {
            get;
            internal set;
        }

        /// <summary>
        /// Gets or sets the logger.
        /// </summary>
        public ILogger Logger
        {
            get;
            set;
        }

        protected Module()
        {
           // IocManager.
        }

     
        /// <summary>
        /// This method is used to register dependencies for this module.
        /// </summary>
        public virtual void Initialize()
        {
        }

     
        /// <summary>
        /// This method is called when the application is being shutdown.
        /// </summary>
        public virtual void Shutdown()
        {
        }
    }
    }
